package com.itfreer.file.download.demo;

import java.io.File;

import android.widget.ProgressBar;

import com.itfreer.file.ProgressListener;
import com.itfreer.file.download.network.FileDownloader;

public class MainActivity {

    private ProgressBar progressBar;

	/**
	 * 带进度条交互的下载
	 * @param path 如： http://www.winrar.com.cn/download/wrar380sc.exe
	 * @param savedir 保存的地方
	 */
    private void download(final String path, final File savedir) {
    	new Thread(new Runnable() {			
			@Override
			public void run() {
				// 第一个参数应该为context参数
				FileDownloader loader = new FileDownloader(null, path, savedir, 3);
		    	progressBar.setMax(loader.getFileSize());
				try {
					loader.download(new ProgressListener() {
						@Override
						public void onDownloadSize(int size) {
							progressBar.setProgress(size);
						}
					});
				} catch (Exception e) {
				}
			}
		}).start();
	}
}